import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '../views/Layout'

// 路由懒加载引入组件
// login
import Login from '@/views/Login'
// layout
import layout from '@/views/Layout'
// home
const home = () => import('@/views/Layout/home/home')
// category
const category = () => import('@/views/Layout/category/category')
const sub = () => import('@/views/Layout/category/sub/sub')
// product
const product = () => import('@/views/Layout/product/product')

const routes = [
  {
    path: '/login',
    component: Login
  }, {
    path: '/',
    component: layout,
    children: [
      {
        // 首页
        path: '',
        component: home
      }, {
        // 分类
        path: 'category/:id',
        component: category
      }, {
        // 分类的选项
        path: 'category/sub/:id',
        component: sub
      }, {
        // 人气推荐
        path: 'product/:id',
        component: product
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior(){
    // vue2.x  用xy控制
    // vue3.x  用left top控制
    return {left:0,top:0}
  }
})

export default router
